﻿package cn.antscript.airCMS.display.component 
{
	import com.bit101.components.ProgressBar;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author antscript
	 */
	public class ProgressPanel extends Sprite
	{
		
		
		private static var _instance:ProgressPanel;
		
		
		private var _bar:ProgressBar;
		
		public function ProgressPanel(privateClass:PrivateClass) 
		{
			_bar = new ProgressBar(this);	
			_bar.maximum = 0;
			_bar.maximum = 1;
			
			this.mouseChildren = false;
			
		}
		
		public static function getInstance():ProgressPanel {
			if (_instance == null) {
				_instance = new ProgressPanel(new PrivateClass);
			}
			return _instance;
		}
		
		public function show(container:DisplayObjectContainer):void {
			
			container.addChild(ProgressPanel.getInstance());			
			
			container.stage.addEventListener(Event.RESIZE, onResize);
			
			onResize();
		}
		public function hide():void {
			
			this.parent.stage.removeEventListener(Event.RESIZE, onResize);
			this.parent.removeChild(this);
		}		
		
		private function onResize(e:Event=null):void 
		{
			graphics.clear();
			graphics.beginFill(0xeeeeee, 0.9);
			graphics.drawRect(0, 0, this.parent.stage.stageWidth, this.parent.stage.stageHeight);
			graphics.endFill();
			
			_bar.x = (this.parent.stage.stageWidth - _bar.width) / 2;
			_bar.y = this.parent.stage.stageHeight / 2;
		}
		
		public function setPro(pro:Number):void {
			_bar.value = pro;
		}
		
		
	}

}

class PrivateClass {
	
}